<?php

namespace backend\controllers;

use yii\web\Controller;
use backend\models\OperForm;
use backend\models\TauOperinfo;
/**
 * #name=网站设置模块#
 */
class MainController extends Controller {
	public $layout='ace';
	/**
	 * #operation=默认操作#
	 */
	public function actionIndex(){
		if(\Yii::$app->user->isGuest){
			$this->redirect(['main/login']);
		}

		return $this->render('index');
	}
	
	/**
	 * #operation=操作员登陆#
	 * 
	 */
	
	public function actionLogin(){
		//不是游客跳转到系统首页
		if(!\Yii::$app->user->isGuest){
			$this->redirect(['main/index']);
		}
		$this->layout='login';
		$model=new OperForm(['scenario'=>'login']);
		if(\Yii::$app->request->isPost){			
			$model->attributes=\Yii::$app->request->post('OperForm');
			
			if($model->validate()&& $model->login()){
				
				$user=TauOperinfo::findOne(['ID',\Yii::$app->user->getId()]);
				\Yii::$app->session->set('ID',\Yii::$app->user->getId());//设置登陆操作员流水号session				
				\Yii::$app->session->set('operID',$user->OperID);//设置操作员编码session
				\Yii::$app->session->set('RoleName',$user->RoleName);//设置操作员角色session				
				\Yii::$app->session->set('operName',$model->username);//设置操作员姓名session
				$this->redirect(['main/index']);//跳转到后台首页
			}
		}
		return $this->render('login',['model'=>$model]);
	}
	/**
	 * #operation=操作员退出#
	 * 
	 */
	public function actionLogout(){
		\Yii::$app->user->logout();
		$this->redirect(['main/login']);
	}
	
	public function actions(){
		return [
		'captcha'=>[
					'class'=>'yii\captcha\CaptchaAction',
					'maxLength'=>4,
					'minLength'=>4
				],
		];
	}
	/**
	 * #operation=错误显示页面#
	 */
	public function actionError(){
		return $this->render('error');
	}
}

?>